import java.io.FileReader;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Vector;

import au.com.bytecode.opencsv.CSVReader;

public class Start 
{
	private static final String AuthorsFile="Authors.csv";

    private static void path(Person p1, Person p2) {
        CoauthorPath cp = new CoauthorPath(p1,p2);
        Person path[] = cp.getPath();
        int i;
        System.out.println("# of Person objects = " + Person.numberOfPersons());
        if (path == null) {
            System.out.println("<"+p1+","+p2+"> not connected");
            return;
        }
        
        for (i=0; i<path.length; i++) {
            System.out.println(i + ": " + path[i] + " " + 
                    path[i].getNumberOfPublications() + " " +
                    (path[i].getPersonRecord()==null?" ":"*"));
        }
        System.out.println();
    }
    
    
    public static void main(String[] args) throws IOException {
//        Person p1, p2, p3;
/*        p1 = Person.create("Michael Ley", "l/Ley:Michael");
        p2 = Person.create("Peter Sturm", "s/Sturm:Peter");
        path(p1,p2);
        p2 = Person.create("Bernd Walter", "w/Walter:Bernd");
        path(p1,p2);
        p2 = Person.create("Alan T. Murray", "m/Murray:Alan_T=");
        path(p1,p2);
        p2 = Person.create("B. Vogel", "v/Vogel:B=");
        path(p1,p2);
        p2 = Person.create("Alan M. Turing", "t/Turing:Alan_M=");
*/        
//        p1 = Person.create("Cagri Ozcaglar", "o/Ozcaglar:Cagri");
//        p2 = Person.create("Kristin P. Bennett", "b/Bennett:Kristin_P=");
//        p3 = Person.create("Jiawei Han", "h/Han:Jiawei");
//
//        //path(p1,p2);
//        Publication[] pubs = p3.getPublications();
//        
//        for(int i=0; i < pubs.length; i++)
//        {
//        	System.out.println(pubs[i].getKey());
//        }
    	
    	Vector<Person> authors = new Vector<Person>();
		HashMap<Person, HashSet<Publication>> authorPubMap = new HashMap<Person, HashSet<Publication>>();
    	CSVReader reader = new CSVReader(new FileReader(AuthorsFile));
		String [] nextLine;
		HashSet<Publication> pubs = new HashSet<Publication>(); 
		HashSet<Publication> allPubs = new HashSet<Publication>(); 
		//System.out.println("test");
		int count = 0;
		while ((nextLine = reader.readNext()) != null) 
		{
			// Clear things
			pubs.clear();
		
			// Creation
			Person p = Person.create(nextLine[0], nextLine[1]);
			authors.add(p);
			//System.out.println(nextLine[0] + "    " +  nextLine[1]);
			pubs = new HashSet<Publication>(Arrays.asList(p.getPublications()));
			allPubs.addAll(pubs);
			authorPubMap.put(p, pubs);
			System.out.println(pubs.size());
			count += pubs.size();
			//p.getPersonRecord().getKey();
			//System.out.println("Name: [" + nextLine[0] + "]\nAddress: [" + nextLine[1] + "]\nEmail: [" + nextLine[2] + "]");
		}
		System.out.println(count);
		System.out.println(allPubs.size());
		
		int count2=0;
		for(Publication pub : allPubs)
		{
			System.out.println(pub.getKey());
			count2++;
			if (count2 > 5)
				break;
		}
    }
}